home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / hotlist.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  2KB  |  94 lines

  1. /* Copyright (C) 2000-1 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: hotlist.c,v 1.36 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include "opennap.h"
  10. #include "hashlist.h"
  11. #include "debug.h"
  12.  
  13. /* 207/208 <nick> */
  14. HANDLER (add_hotlist)
  15. {
  16.     hashlist_t *hotlist;
  17.     USER   *user;
  18.     LIST   *list;
  19.     int     count;
  20.  
  21.     (void) tag;
  22.     (void) len;
  23.     ASSERT (validate_connection (con));
  24.     CHECK_USER_CLASS ("add_hotlist");
  25.  
  26.     if (invalid_nick (pkt))
  27.     {
  28.     send_cmd (con, MSG_SERVER_NOSUCH, "hotlist add failed: invalid nick");
  29.     return;
  30.     }
  31.  
  32.     /* check to see if this user is over the hotlist limit */
  33.     if (Max_Hotlist > 0
  34.     && (count = list_count (con->uopt->hotlist)) > Max_Hotlist)
  35.     {
  36.     /* send_cmd (con, MSG_SERVER_HOTLIST_ERROR, "%s", pkt); */
  37.     return;
  38.     }
  39.  
  40.     hotlist = hashlist_add (Hotlist, pkt, con);
  41.     if (!hotlist)
  42.     {
  43.     /* already on list, or failure */
  44.     return;
  45.     }
  46.     ASSERT (hashlist_validate (hotlist));
  47.  
  48.     /* add the hotlist entry to this particular users list */
  49.     list = MALLOC (sizeof (LIST));
  50.     if (!list)
  51.     {
  52.     OUTOFMEMORY ("add_hotlist");
  53.     hashlist_remove (Hotlist, pkt, con);
  54.     send_cmd (con, MSG_SERVER_HOTLIST_ERROR, "%s", pkt);
  55.     return;
  56.     }
  57.     list->data = hotlist;
  58.     con->uopt->hotlist = list_push (con->uopt->hotlist, list);
  59.  
  60.     /* ack the user who requested this */
  61.     send_cmd (con, MSG_SERVER_HOTLIST_ACK, "%s", hotlist->key);
  62.  
  63.     /* check to see if this user is on so the client is notified
  64.        immediately */
  65.     user = hash_lookup (Users, hotlist->key);
  66.     if (user)
  67.     {
  68.     ASSERT (validate_user (user));
  69.     send_cmd (con, MSG_SERVER_USER_SIGNON, "%s %d", user->nick,
  70.           user->speed);
  71.     }
  72. }
  73.  
  74. /* 303 <nick> */
  75. HANDLER (remove_hotlist)
  76. {
  77.     hashlist_t *hotlist;
  78.  
  79.     (void) tag;
  80.     (void) len;
  81.     ASSERT (validate_connection (con));
  82.     CHECK_USER_CLASS ("remove_hotlist");
  83.  
  84.     hotlist = hash_lookup (Hotlist, pkt);
  85.     if (!hotlist)
  86.     return;
  87.     ASSERT (hashlist_validate (hotlist));
  88.  
  89.     /* remove the hotlist entry from the user's personal list */
  90.     con->uopt->hotlist = list_delete (con->uopt->hotlist, hotlist);
  91.  
  92.     hashlist_remove (Hotlist, hotlist->key, con);
  93. }
  94.